package com.lmpop.createIndex.search;

import com.lmpop.createIndex.searchModel.Queue;
import com.lmpop.createIndex.searchModel.QueueValue;
import com.lmpop.createIndex.searchModel.SearchData;
import com.lmpop.createIndex.searchModel.SearchModel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class AttachIndexFiles
{
  public ProperUtil properUtil;
  private String file_path;

  public AttachIndexFiles()
  {
    this.properUtil = new ProperUtil();
    this.file_path = this.properUtil.getFilePathByModel("attach");
  }

  public String getFilepathById(String attach_root_id) throws IOException {
    if (attach_root_id.equals("")) return "";
    SearchData search = new SearchData();
    ArrayList paraList = new ArrayList();
    paraList.add(new SearchModel("0", "attach_root_id", attach_root_id));
    ArrayList list = search.getSearchInfo(this.file_path, paraList);
    String file_path = "";
    if ((list != null) && (list.size() > 0)) {
      Hashtable map = (Hashtable)list.get(0);
      if (map.get("file_path") != null) file_path = map.get("file_path").toString();
    }
    return file_path;
  }

  public List getAttachList(Map paraMap) throws IOException {
    ArrayList showList = new ArrayList();
    SearchData search = new SearchData();
    ArrayList paraList = new ArrayList();

    String attach_id = ""; String attach_root_id = ""; String attach_name = ""; String orderby = "in_date"; String file_type = "";
    String rsrv_str1 = ""; String rsrv_str6 = ""; String rsrv_str7 = ""; String rsrv_str8 = ""; String cust_id = "";
    boolean sort_type = true;

    if (paraMap.get("attach_id") != null) attach_id = paraMap.get("attach_id").toString();
    if (paraMap.get("cust_id") != null) cust_id = paraMap.get("cust_id").toString();
    if (paraMap.get("attach_root_id") != null) attach_root_id = paraMap.get("attach_root_id").toString();
    if (paraMap.get("attach_name") != null) attach_name = paraMap.get("attach_name").toString();
    if (paraMap.get("file_type") != null) file_type = paraMap.get("file_type").toString();
    if (paraMap.get("rsrv_str1") != null) rsrv_str1 = paraMap.get("rsrv_str1").toString();
    if (paraMap.get("rsrv_str6") != null) rsrv_str6 = paraMap.get("rsrv_str6").toString();
    if (paraMap.get("rsrv_str7") != null) rsrv_str7 = paraMap.get("rsrv_str7").toString();
    if (paraMap.get("rsrv_str8") != null) rsrv_str8 = paraMap.get("rsrv_str8").toString();
    if (paraMap.get("orderby") != null) orderby = paraMap.get("orderby").toString();
    if (paraMap.get("sort_type") != null) sort_type = new Boolean(paraMap.get("sort_type").toString()).booleanValue();

    Queue queue = new Queue(new QueueValue[] { new QueueValue(orderby, 2, sort_type) });

    paraList.add(new SearchModel("0", "attach_id", attach_id));
    paraList.add(new SearchModel("0", "cust_id", cust_id));
    paraList.add(new SearchModel("0", "attach_root_id", attach_root_id));
    paraList.add(new SearchModel("0", "file_type", file_type));
    paraList.add(new SearchModel("0", "rsrv_str1", rsrv_str1));
    paraList.add(new SearchModel("0", "rsrv_str6", rsrv_str6));
    paraList.add(new SearchModel("0", "rsrv_str7", rsrv_str7));
    paraList.add(new SearchModel("0", "rsrv_str8", rsrv_str8));
    paraList.add(new SearchModel("2", attach_name, new String[] { "attach_name", "attach_name" }));

    showList = search.getSearchInfo(this.file_path, paraList, queue);

    return showList;
  }
}